package test;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class Druid {
    @Test
    public void druid() throws SQLException {
        Properties properties=new Properties();
        InputStream is=Druid.class.getClassLoader().getResourceAsStream("src/durid.properties");
        try {
            properties.load(is);
            DataSource ds= DruidDataSourceFactory.createDataSource(properties);

            Connection connection=ds.getConnection();
            PreparedStatement preparedStatement=connection.prepareStatement("select *from student");
            ResultSet resultSet=preparedStatement.executeQuery();

            while (resultSet.next()){
                System.out.println(resultSet.getInt("id")+"--"+resultSet.getString("name")+"--"+resultSet.getInt("age"));
            }
            connection.close();
        } catch (IOException e){
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
